//
//  WLCWebViewController.m
//  StudyTogether
//
//  Created by Mr.Lee on 2019/6/4.
//  Copyright © 2019 Scott. All rights reserved.
//

#import "WLCWebViewController.h"
#import "NJKWebViewProgressView.h"
#import "NJKWebViewProgress.h"

@interface WLCWebViewController ()

{
    NJKWebViewProgressView *_progressView;
    NJKWebViewProgress *_progressProxy;
}

@property (strong, nonatomic) UIWebView *webView;


@end

@implementation WLCWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self makeWeb];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)makeWeb {
    _webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _webView.delegate = (id)self;
    _webView.scalesPageToFit = YES;
    [self.view addSubview:_webView];
    NSURL *url = [NSURL URLWithString:self.content];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    _progressProxy = [[NJKWebViewProgress alloc] init];
    _webView.delegate = _progressProxy;
    _progressProxy.webViewProxyDelegate = (id)self;
    _progressProxy.progressDelegate = (id)self;
    
    CGRect rect = [[UIApplication sharedApplication] statusBarFrame];
    CGRect barFrame = CGRectMake(0, rect.size.height+1, [UIScreen mainScreen].bounds.size.width, 3);
    _progressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame];
    _progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    [_webView addSubview:_progressView];
    _progressView.progress = 0;
    
    [_webView loadRequest:request];
}

#pragma mark - NJKWebViewProgressDelegate
- (void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
    [_progressView setProgress:progress animated:YES];
}

@end
